frida_selinux_incdir = include_directories('include')

selinux_sources = [
  'src/selinux/avc.c',
  'src/selinux/avc_internal.c',
  'src/selinux/avc_sidtab.c',
  'src/selinux/booleans.c',
  'src/selinux/callbacks.c',
  'src/selinux/canonicalize_context.c',
  'src/selinux/checkAccess.c',
  'src/selinux/check_context.c',
  'src/selinux/compute_av.c',
  'src/selinux/compute_create.c',
  'src/selinux/context.c',
  'src/selinux/deny_unknown.c',
  'src/selinux/disable.c',
  'src/selinux/enabled.c',
  'src/selinux/fgetfilecon.c',
  'src/selinux/freecon.c',
  'src/selinux/fsetfilecon.c',
  'src/selinux/get_initial_context.c',
  'src/selinux/getenforce.c',
  'src/selinux/getfilecon.c',
  'src/selinux/getpeercon.c',
  'src/selinux/init.c',
  'src/selinux/lgetfilecon.c',
  'src/selinux/load_policy.c',
  'src/selinux/lsetfilecon.c',
  'src/selinux/mapping.c',
  'src/selinux/policyvers.c',
  'src/selinux/procattr.c',
  'src/selinux/sestatus.c',
  'src/selinux/setenforce.c',
  'src/selinux/setfilecon.c',
  'src/selinux/stringrep.c',
  'src/selinux/xattr.c',
]
selinux = static_library('selinux', selinux_sources,
  include_directories: frida_selinux_incdir,
)

sepol_modern_sources = [
  'src/sepol-modern/assertion.c',
  'src/sepol-modern/avrule_block.c',
  'src/sepol-modern/avtab.c',
  'src/sepol-modern/boolean_record.c',
  'src/sepol-modern/booleans.c',
  'src/sepol-modern/conditional.c',
  'src/sepol-modern/constraint.c',
  'src/sepol-modern/context.c',
  'src/sepol-modern/context_record.c',
  'src/sepol-modern/debug.c',
  'src/sepol-modern/ebitmap.c',
  'src/sepol-modern/expand.c',
  'src/sepol-modern/handle.c',
  'src/sepol-modern/hashtab.c',
  'src/sepol-modern/hierarchy.c',
  'src/sepol-modern/iface_record.c',
  'src/sepol-modern/interfaces.c',
  'src/sepol-modern/link.c',
  'src/sepol-modern/mls.c',
  'src/sepol-modern/module.c',
  'src/sepol-modern/module_to_cil.c',
  'src/sepol-modern/node_record.c',
  'src/sepol-modern/nodes.c',
  'src/sepol-modern/polcaps.c',
  'src/sepol-modern/policydb.c',
  'src/sepol-modern/policydb_convert.c',
  'src/sepol-modern/policydb_public.c',
  'src/sepol-modern/port_record.c',
  'src/sepol-modern/ports.c',
  'src/sepol-modern/roles.c',
  'src/sepol-modern/services.c',
  'src/sepol-modern/sidtab.c',
  'src/sepol-modern/symtab.c',
  'src/sepol-modern/user_record.c',
  'src/sepol-modern/users.c',
  'src/sepol-modern/util.c',
  'src/sepol-modern/write.c',
]
sepol_modern = static_library('sepol-modern', sepol_modern_sources,
  include_directories: include_directories('src/sepol-modern', 'src/sepol-modern/include'),
)

sepol_legacy_sources = [
  'src/sepol-legacy/assertion.c',
  'src/sepol-legacy/avrule_block.c',
  'src/sepol-legacy/avtab.c',
  'src/sepol-legacy/boolean_record.c',
  'src/sepol-legacy/booleans.c',
  'src/sepol-legacy/conditional.c',
  'src/sepol-legacy/constraint.c',
  'src/sepol-legacy/context.c',
  'src/sepol-legacy/context_record.c',
  'src/sepol-legacy/debug.c',
  'src/sepol-legacy/ebitmap.c',
  'src/sepol-legacy/expand.c',
  'src/sepol-legacy/handle.c',
  'src/sepol-legacy/hashtab.c',
  'src/sepol-legacy/hierarchy.c',
  'src/sepol-legacy/iface_record.c',
  'src/sepol-legacy/interfaces.c',
  'src/sepol-legacy/link.c',
  'src/sepol-legacy/mls.c',
  'src/sepol-legacy/module.c',
  'src/sepol-legacy/module_to_cil.c',
  'src/sepol-legacy/node_record.c',
  'src/sepol-legacy/nodes.c',
  'src/sepol-legacy/polcaps.c',
  'src/sepol-legacy/policydb.c',
  'src/sepol-legacy/policydb_convert.c',
  'src/sepol-legacy/policydb_public.c',
  'src/sepol-legacy/port_record.c',
  'src/sepol-legacy/ports.c',
  'src/sepol-legacy/roles.c',
  'src/sepol-legacy/services.c',
  'src/sepol-legacy/sidtab.c',
  'src/sepol-legacy/symtab.c',
  'src/sepol-legacy/user_record.c',
  'src/sepol-legacy/users.c',
  'src/sepol-legacy/util.c',
  'src/sepol-legacy/write.c',
]
sepol_legacy = static_library('sepol-legacy', sepol_legacy_sources,
  c_args: ['-include', 'sepol-legacy-renames.h'],
  include_directories: include_directories('src/sepol-legacy', 'src/sepol-legacy/include'),
)

frida_selinux_modern = static_library('frida-selinux-modern', 'src/patch.c',
  c_args: ['-DFRIDA_SELINUX_MODERN'] + frida_component_cflags,
  include_directories: [frida_selinux_incdir, include_directories('src/sepol-modern/include')],
  link_with: sepol_modern,
  dependencies: [glib_dep],
)

frida_selinux_legacy = static_library('frida-selinux-legacy', 'src/patch.c',
  c_args: ['-DFRIDA_SELINUX_LEGACY', '-include', 'sepol-legacy-renames.h'] + frida_component_cflags,
  include_directories: [frida_selinux_incdir, include_directories('src/sepol-legacy/include')],
  link_with: sepol_legacy,
  dependencies: [glib_dep],
)

install_headers('include/frida-selinux.h', subdir: 'frida-' + api_version)

frida_selinux_sources = [
  'src/dispatch.c',
]
frida_selinux = static_library('frida-selinux', 'src/dispatch.c',
  c_args: frida_component_cflags,
  include_directories: frida_selinux_incdir,
  link_with: [selinux, frida_selinux_modern, frida_selinux_legacy],
  dependencies: [glib_dep],
)

frida_selinux_dep = declare_dependency(
  include_directories: frida_selinux_incdir,
  link_with: frida_selinux,
  dependencies: [glib_dep],
)

frida_selinux_vala_args = ['--vapidir=' + join_paths(meson.current_source_dir(), 'vapi'), '--pkg=libselinux']
